package hn.cch.mybatis.interceptor;

import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Plugin;
import org.apache.ibatis.plugin.Signature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Properties;
import java.util.concurrent.Executor;


@Intercepts(value = {
    @Signature(
        type = Executor.class,
        method = "select",
        args = {
            MappedStatement.class, Object.class
        })
})
public class CustomInterceptor implements Interceptor {

    private static final Logger logger = LoggerFactory.getLogger(CustomInterceptor.class);


    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        logger.info("invocation:{}", invocation.toString());
        return invocation.proceed();
    }

    @Override
    public Object plugin(Object target) {
        logger.info("target:{}", target.toString());
        return Plugin.wrap(target, this);
    }

    @Override
    public void setProperties(Properties properties) {
        logger.info("properties:{}", properties.toString());
    }

}
